<template>
  <div class="altimeter">
    <div class="scale-wrapper">
      <div class="center-indicator"></div>
      <div class="scale">
        <div v-for="mark in visibleMarks" :key="mark.altitude" class="scale-mark" :class="{ 'major-mark': mark.major }"
          :style="{ top: `${50 + (altitude - mark.altitude) * 1.5}%` }">
          <div v-if="mark.major" class="mark-line" :class="{ 'major-line': mark.major }"></div>
          <span v-if="mark.major">{{ mark.altitude }}</span>
        </div>
      </div>
    </div>
    <div class="altitude-value">{{ Math.round(altitude) }}</div>
  </div>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  altitude: {
    type: Number,
    default: 0
  },
  visibleRange: {
    type: Number,
    default: 50
  },
  majorStep: {
    type: Number,
    default: 10
  }
});

const visibleMarks = computed(() => {
  const marks = [];
  const start = Math.floor(props.altitude) - props.visibleRange;
  const end = Math.floor(props.altitude) + props.visibleRange;

  for (let alt = start; alt <= end; alt++) {
    marks.push({
      altitude: alt,
      major: alt % props.majorStep === 0
    });
  }

  return marks;
});
</script>

<style lang="scss" scoped>
.altimeter {
  display: flex;
  width: 100%;
  height: 100%;
  font-family: 'Arial', sans-serif;

  .altitude-value {
    width: 30%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8vh;
    font-weight: bold;
  }

  .scale-wrapper {
    position: relative;
    width: 70%;
    height: 100%;
    overflow: hidden;

    .center-indicator {
      position: absolute;
      left: 0;
      top: 50%;
      width: 100%;
      height: 0.1vh;
      background: red;
      z-index: 2;
    }

    .scale {
      position: relative;
      height: 100%;
      width: 100%;
      border-left: 0.01vh solid #ffffff;

      .scale-mark {
        position: absolute;
        right: 0;
        width: 100%;
        height: 20px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        transition: top 0.3s ease-out;
        transform: translateY(-50%);

        &.major-mark {
          font-weight: bold;

          span {
            margin-left: 0.5vh;
            font-size: 1vh;
          }
        }

        .mark-line {
          width: 0.5vh;
          height: 0.01vh;
          background: #ffffff;
          // margin-right: 5px;

        }

        .major-line {
          background: #ffffff;
          width: 1vh;
          height: 0.1vh;
        }
      }
    }
  }
}
</style>